<?php

require_once( $_SERVER['DOCUMENT_ROOT'].'/libs/smarty.inc' );

require_once( $_SERVER['DOCUMENT_ROOT'].'/libs/smt_variables.php' );

require_once( $_SERVER['DOCUMENT_ROOT'].'/libs/Class_DB.php' );

require_once( $_SERVER['DOCUMENT_ROOT'].'/libs/Class_ERROR.php' );

require_once( $_SERVER['DOCUMENT_ROOT'].'/libs/login.inc.php' );



if( !in_array( "M", $_SESSION['ADMIN_LOGIN']['AUTH_CD'] ) ) exit;

$mystaff_id = $_SESSION['ADMIN_LOGIN']['STAFF_ID'] ;

if( $_SERVER['REQUEST_METHOD'] == 'POST' ){

	$forms = $_POST;
	$company_name = $_POST["company_name"];
	$katakana = $_POST["katakana"];
	$branch_name = $_POST["branch_name"];
	$sal_manager = $_POST["sal_manager"];
	$r_date1 = $_POST["r_date1"];
	$r_date2 = $_POST["r_date2"];
	$u_date1 = $_POST["u_date1"];
	$u_date2 = $_POST["u_date2"];
	
	$price_no = $_POST['price_no'];
	$pro_name = $_POST['pro_name'];
	$category = $_POST['category'];
	$m_date1 = $_POST['m_date1'];
	$m_date2 = $_POST['m_date2'];
	$u_date3 = $_POST["u_date3"];
	$u_date4 = $_POST["u_date4"];
	$producer = $_POST['producer'];
	$status = $_POST['status'];
	$e_date1 = $_POST['e_date1'];
	$e_date2 = $_POST['e_date2'];
	$u_date5 = $_POST["u_date5"];
	$u_date6 = $_POST["u_date6"];
	

	
	//SQLクエリー
	$sql = "SELECT * FROM p_consumer A,p_consumer_detail B WHERE 1 = 1 and A.consumer_id = B.consumer_id  ";	
	//echo $sql;
	if($company_name != null){
		$sql = $sql." and A.company_name like '%".$company_name."%'";		
	}
	if($katakana != null){
		$sql = $sql." and A.katakana like '%".$katakana."%'";	
	}
	if($branch_name != null){
		$sql = $sql." and A.branch_name like '%".$branch_name."%'";			
	}
	if($sal_manager != null){
		$sql = $sql." and A.sal_manager like '%".$sal_manager."%'";	
	}
	if($r_date1 != null || $r_date2 != null){
		$sql = $sql." and A.r_date BETWEEN '".$r_date1."' and '".$r_date2."'";	
	}
	
	
	if($price_no != null){
		$sql = $sql." and B.price_no ='".$price_no."'";		
	}
	if($pro_name != null){
		$sql = $sql." and B.pro_name like '%".$pro_name."%'";		
	}
	if($category != null){
		$sql = $sql." and B.category = '%".$category."%'";		
	}
	if($m_date1 != null || $m_date2 != null){
		$sql = $sql." and B.m_date BETWEEN '".$m_date1."' and '".$m_date2."'";	
	}
	if($u_date3 != null || $u_date4 != null){
		$sql = $sql." and B.u_date BETWEEN '".$u_date3."' and '".$u_date4."'";	
	}
	if($producer != null){
		$sql = $sql." and B.producer like '%".$producer."%'";		
	}
	if($status != null){
		$sql = $sql." and B.status like '%".$status."%'";		
	}
	if($e_date1 != null || $e_date2 != null){
		$sql = $sql." and B.e_date BETWEEN '".$e_date1."' and '".$e_date2."'";	
	}
	if($u_date5 != null || $u_date6 != null){
		$sql = $sql." and B.u_date BETWEEN '".$u_date5."' and '".$u_date6."'";	
	}
	
	
	$sql = $sql."  order by A.u_date desc";
	

	
	$db = new Class_DB;		
		
	$res = $db->query($sql);
	
	$cnt = 0;
	
	
	
	while( $row = mysql_fetch_array($res,MYSQL_ASSOC) ){		
		
		//1生産、②承認申請、3は承認、4承認が却下;5カスタマーOK]を、6顧客のNG
		if($row['status']==1){
			$opt = "<label><input type=\"hidden\" name=\"status\" value=\"1\">生産</input></label>";

		}elseif ($row['status']==2){
			$opt = "<label><input type=\"hidden\" name=\"status\" value=\"2\">承認申請</input></label>";

		}elseif ($row['status']==3){
			$opt = "<label><input type=\"hidden\" name=\"status\" value=\"3\">は承認</input></label>";

		}elseif ($row['status']==4){
			$opt = "<label><input type=\"hidden\" name=\"status\" value=\"4\">承認が却下</input></label>";

		}elseif ($row['status']==5){
			$opt = "<label><input type=\"hidden\" name=\"status\" value=\"5\">OK</input></label>";

		}elseif ($row['status']==6){
			$opt = "<label><input type=\"hidden\" name=\"status\" value=\"6\">NG</input></label>";

		}else{
			$opt = "<label><input type=\"hidden\" name=\"status\" value=\"0\">まだ治療</input></label>";
		}
		$row['opt'] = $opt;
		
		$resultlist[] = $row;
	
		$cnt++;		
		
	}
	
}


$menu_html = file_get_contents( $_SERVER['DOCUMENT_ROOT'].'/templates/web-admin/menu.html' );

$smarty->assign('menu_html', $menu_html);

$smarty->assign('resultlist', $resultlist);

$smarty->assign('cnt', $cnt);

$smarty->assign('mystaff_id', $mystaff_id);

$smarty->display('web-admin/check_result.html');


?>